package so.sao.code.service;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import java.util.concurrent.TimeUnit;

/**
 * 定义项目应用到的线程池
 * 
 */
//TODO spring 中有现成的。注入即可。参考 AsyncConfigurer和EnableAsync, Executor和TaskExecutor现在@Async用的是sleuth中线程。
@Deprecated
public class AppExecutors {

    private final static BlockingQueue<Runnable> traceQueue = new ArrayBlockingQueue<>(100, true);

    //TODO 需重新严格确定参数大小。
    private static ExecutorService taskPoolExecutor = new ThreadPoolExecutor(1, 5, 2, TimeUnit.MINUTES, traceQueue,
            new CallerRunsPolicy());

    /**
     * 
     * @return
     */
    public static ExecutorService getTaskPoolExecutor() {
        return taskPoolExecutor;
    }
}
